package com.example.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.net.InetAddress;
import java.net.UnknownHostException;

public class IPUtils {

    static Logger logger = LoggerFactory.getLogger(IPUtils.class);

    public static String getLocalIP() {
        String ip = "127.0.0.1";
        try {
            InetAddress localHost = InetAddress.getLocalHost();
            ip = localHost.getHostAddress();
        } catch (UnknownHostException e) {
            logger.info("获取本地IP异常: " + e.getMessage());
        }
        return ip;
    }
}
